package com.ruoyi.wb.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbComplaint;
import com.ruoyi.wb.service.IWbComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投诉建议Controller
 * 
 * @author ruoyi
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/system/complaint")
public class WbComplaintController extends BaseController
{
    @Autowired
    private IWbComplaintService wbComplaintService;

    /**
     * 查询投诉建议列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbComplaint wbComplaint)
    {
        startPage();
        List<WbComplaint> list = wbComplaintService.selectWbComplaintList(wbComplaint);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbComplaint wbComplaint)
    {
        List<WbComplaint> list = wbComplaintService.selectWbComplaintList(wbComplaint);
        ExcelUtil<WbComplaint> util = new ExcelUtil<WbComplaint>(WbComplaint.class);
        util.exportExcel(response, list, "投诉建议数据");
    }

    /**
     * 获取投诉建议详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbComplaintService.selectWbComplaintById(id));
    }

    /**
     * 新增投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbComplaint wbComplaint)
    {
        return toAjax(wbComplaintService.insertWbComplaint(wbComplaint));
    }

    /**
     * 修改投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbComplaint wbComplaint)
    {
        return toAjax(wbComplaintService.updateWbComplaint(wbComplaint));
    }

    /**
     * 删除投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbComplaintService.deleteWbComplaintByIds(ids));
    }
}
